﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComputerGraphics.Graphics;
using ComputerGraphics.Utils;

namespace ComputerGraphics.Geometry
{
    public class Circle : Plane
    {
        private Point3D center;
        private double sqrRadius;

        public Circle(Point3D center, Point3D normal, double radius, Texture texture)
            : base(center, normal, texture)
        {
            this.center = center;
            this.sqrRadius = radius * radius;
        }

        public override Intersection Intersect(Ray r)
        {
            Intersection ret = base.Intersect(r);

            if (ret != null)
            {
                double dist = (ret.Position - center).SquareNorm;

                if (MathUtils.GetZeroDouble(dist - sqrRadius) > 0) ret = null;
            }

            return ret;
        }
    }
}
